package com.controller;

import com.domain.ChatRoomEntity;
import com.dto.JsonResponse;
import com.dto.PageResult;
import com.service.ChatRoomService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 聊天室房间表 前端控制器
 * </p>
 *
 * @author sly
 * @since 2023-12-30
 */
@RestController
@RequestMapping("/chat")
public class ChatRoomController {

    @Autowired
    private ChatRoomService chatRoomService;

    /**
     * 查询直播列表
     */
    @PostMapping("/pageListChat")
    public JsonResponse<PageResult<ChatRoomEntity>> pageListChat(@RequestBody ChatRoomEntity chat) {
        PageResult<ChatRoomEntity> result = chatRoomService.pageListChat(chat);
        return new JsonResponse<>(result);
    }

    /**
     * 查询直播详情
     */
    @GetMapping("/getChatDetail")
    public JsonResponse<ChatRoomEntity> getChatDetail(@RequestParam Long chatId) {
        ChatRoomEntity result = chatRoomService.getChatDetail(chatId);
        return new JsonResponse<>(result);
    }

    /**
     * 新增直播
     */
    @PostMapping("/addChat")
    public JsonResponse<String> addChat(@RequestBody ChatRoomEntity chat) {
        chatRoomService.addChat(chat);
        return JsonResponse.success();
    }

    /**
     * 修改直播信息
     */
    @PostMapping("/updateChat")
    public JsonResponse<String> updateChat(@RequestBody ChatRoomEntity chat) {
        chatRoomService.updateChat(chat);
        return JsonResponse.success();
    }

    /**
     * 删除直播
     */
    @GetMapping("/deleteChat")
    public JsonResponse<String> deleteChat(@RequestParam Long chatId) {
        chatRoomService.deleteChat(chatId);
        return JsonResponse.success();
    }
}
